package com.dries.portal.module.user.bo;

import com.dries.portal.module.user.entity.UserEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Arrays;
import java.util.Collection;

/**
 * @Description: @Author ZSY
 *
 * @createTime 2020/6/28 17:13
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
public class PortalUserDetails implements UserDetails {

  private UserEntity user;

  @Override
  public Collection<? extends GrantedAuthority> getAuthorities() {
    // 返回当前用户的权限
    return Arrays.asList(new SimpleGrantedAuthority("TEST"));
  }

  @Override
  public String getPassword() {
    return user.getPassword();
  }

  @Override
  public String getUsername() {
    return user.getUsername();
  }

  @Override
  public boolean isAccountNonExpired() {
    return true;
  }

  @Override
  public boolean isAccountNonLocked() {
    return true;
  }

  @Override
  public boolean isCredentialsNonExpired() {
    return true;
  }

  @Override
  public boolean isEnabled() {
    return true;
  }
}
